/*
 * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package top.continew.admin.hanfu.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.continew.admin.hanfu.domain.Tips;
import top.continew.admin.hanfu.domain.bo.TipsBo;
import top.continew.admin.hanfu.domain.vo.TipsVo;
import top.continew.admin.hanfu.domain.vo.wx.TipsWxVo;
import top.continew.admin.hanfu.mapper.TipsMapper;
import top.continew.admin.hanfu.service.ITipsService;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author bbm
 * @since 2025-04-15
 */
@Service
@RequiredArgsConstructor
public class TipsServiceImpl extends ServiceImpl<TipsMapper, Tips> implements ITipsService {

    private final TipsMapper tipsMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addTips(Tips tips) {
        boolean save = save(tips);

        if (!save) {
            throw new RuntimeException("添加小贴士失败");
        }

    }

    @Override
    @Transactional
    public void delTips(Integer id) {
        boolean b = removeById(id);
        if (!b) {
            throw new RuntimeException("删除小贴士失败");
        }
    }

    @Override
    public void putTips(Tips tips) {
        boolean b = updateById(tips);
        if (!b) {
            throw new RuntimeException("修改小贴士失败");
        }
    }

    @Override
    public Page<TipsVo> getTipsPage(Page<TipsVo> page, TipsBo bo) {
        return tipsMapper.getTipsPageByQuery(page, bo);
    }

    @Override
    public Page<TipsWxVo> getTipsWxPage(Page<TipsWxVo> page, TipsBo bo) {
        return tipsMapper.getTipsPageByWxQuery(page, bo);
    }

}
